%Declare the symbolic variables (syms)
syms PbVal PbLeadVal RVal %rVal PiLeadVal
%f= -Pb*exp(PbVal) + (1+rho * Pb*exp(PbLeadVal)) / (r*exp(rVal) * PI*exp(PiLeadVal));
f= -Pb*exp(PbVal) + (1+rho * Pb*exp(PbLeadVal)) / (R*exp(RVal));

%Take symbolic derivatives
dd1 = diff(f,PbVal);
dd2 = diff(f,PbLeadVal);
% dd3 = diff(f,rVal);
% dd4 = diff(f,PiLeadVal);
dd3=diff(f,RVal);

%Evaluates symbolic derivatives

PbVal=0;  %loglin
PbLeadVal=0;  %loglin
% rVal=0;  %loglin
% PiLeadVal=0; %loglin
RVal=0;


D1=subs(dd1);
D2=subs(dd2);
% D3=subs(dd3);
% D4=subs(dd4);
D3=subs(dd3);

% Transform symbolic into numbers (with double precision)
d1=double(D1);
d2=double(D2);
% d3=double(D3);
% d4=double(D4);
d3=double(D3);

ACont(ii,pbLog)        = d1;
ALead(ii,pbLog)       = d2;
% ACont(ii,rLog)        = d3;
% ALead(ii,PiLog)        = d4;
ACont(ii,RLog)        =d3;